package com.ruoyi.project.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.project.vo.CompomentInfoListVO;
import com.ruoyi.project.vo.CompomentInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.mapper.CompomentInfoMapper;
import com.ruoyi.project.domain.CompomentInfo;
import com.ruoyi.project.service.ICompomentInfoService;

/**
 * 构件维护Service业务层处理
 * 
 * @author LiuDongyi
 * @date 2022-08-27
 */
@Service
public class CompomentInfoServiceImpl implements ICompomentInfoService 
{
    @Autowired
    private CompomentInfoMapper compomentInfoMapper;

    /**
     * 查询构件维护
     * 
     * @param id 构件维护主键
     * @return 构件维护
     */
    @Override
    public CompomentInfo selectCompomentInfoById(Long id)
    {
        return compomentInfoMapper.selectCompomentInfoById(id);
    }

    /**
     * 查询构件维护列表
     * 
     * @param compomentInfo 构件维护
     * @return 构件维护
     */
    @Override
    public List<CompomentInfoListVO> selectCompomentInfoList(CompomentInfoListVO compomentInfoListVO)
    {
        List<CompomentInfoListVO> compomentInfoListVOS = compomentInfoMapper.selectCompomentInfoList(compomentInfoListVO);
        for (CompomentInfoListVO c:compomentInfoListVOS){
            CompomentInfoListVO compomentInfoListVO1=compomentInfoMapper.selectCount(c.getProjectNo(),c.getCompomentNo());
            c.setCount(compomentInfoListVO1.getCount());
            c.setYieldCount(compomentInfoListVO1.getYieldCount());
        }
        return compomentInfoListVOS;
    }

    /**
     * 新增构件维护
     * 
     * @param compomentInfo 构件维护
     * @return 结果
     */
    @Override
    public int insertCompomentInfo(CompomentInfo compomentInfo)
    {
        compomentInfo.setCreateTime(DateUtils.getNowDate());
        return compomentInfoMapper.insertCompomentInfo(compomentInfo);
    }

    /**
     * 修改构件维护
     * 
     * @param compomentInfo 构件维护
     * @return 结果
     */
    @Override
    public int updateCompomentInfo(CompomentInfo compomentInfo)
    {
        compomentInfo.setUpdateTime(DateUtils.getNowDate());

        SysUser user = SecurityUtils.getLoginUser().getUser();
        compomentInfo.setUpdateBy(user.getUserName());
        return compomentInfoMapper.updateCompomentInfo(compomentInfo);
    }

    /**
     * 批量删除构件维护
     * 
     * @param ids 需要删除的构件维护主键
     * @return 结果
     */
    @Override
    public int deleteCompomentInfoByIds(Long[] ids)
    {
        for (int i=0;i<ids.length;i++){
            CompomentInfo compomentInfo = compomentInfoMapper.selectCompomentInfoById(ids[i]);
            compomentInfoMapper.deleteprojectModelInfoByCompomentNo(compomentInfo.getCompomentNo());
        }
        return compomentInfoMapper.deleteCompomentInfoByIds(ids);
    }

    /**
     * 删除构件维护信息
     * 
     * @param id 构件维护主键
     * @return 结果
     */
    @Override
    public int deleteCompomentInfoById(Long id)
    {
        return compomentInfoMapper.deleteCompomentInfoById(id);
    }

    @Override
    public List<CompomentInfoVO> selectCompomentInfoVOList(CompomentInfoVO compomentInfoVO) {
        return compomentInfoMapper.selectCompomentInfoVOList(compomentInfoVO);
    }
}
